package com.ls.utils.sms;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import javax.validation.constraints.*;
import java.util.List;
import java.util.Random;

/**
 * @ClassName BookSendSmsModel
 * @Description 发送短信model
 * @Author pengyu
 * @Date 2019/9/13 10:17
 * @Version 1.0
 **/
@Data
@NoArgsConstructor  // 新增无参构造
@AllArgsConstructor // 补充全参构造
@Slf4j
public class SendSmsModel {

    public static final String DEFAULT_CALL_NO ="02312345678";
    public static final String PREFIX_CONTENT ="【四川电信】";
    /** 通讯云助手去电短信 */
    public static final String VERIFY_CODE_PREFIX = "【乐信通】尊敬的用户您好，您的验证码为 ";

    /**
     * 下游服务主键ID
     */
    @NotNull(message = "下游业务Id不能为空")
    private Long serviceId = 35L;

    /**
     * 账号
     */
    @NotEmpty(message = "账号不能为空")
    private String account = "lexintong";

    /**
     * 密码
     */
    @NotEmpty(message = "密码不能为空")
    private String password = "qwer3324";

    /**
     * 主叫号码
     */
    @NotEmpty(message = "主叫号码不能为空")
    private String callNo = DEFAULT_CALL_NO;

    /**
     * 被叫号码
     */
    @NotEmpty(message = "被叫号码不能为空")
    private String mobile;

    /**
     * 被叫号码列表
     */
//    @NotEmpty(message = "被叫号码不能为空")
    private List<String> mobileArray;

    /**
     * 内容
     */
    @NotNull(message = "发送内容不能为空")
    @Size(max = 136,message = "不能超过136个字符")
    private String content;
    /**
     * 短信类型 1 营销短信（包括验证码），默认； 2 5g短信
     */
    @NotNull(message = "短信类型不能为空")
    @Min(value = 1,message = "短信类型不能小于1")
    @Max(value = 2,message = "短信类型不能大于2")
    private Integer smsType;

    /**只是本地存储用*/
    private String validCode;
    public SendSmsModel(@NotEmpty(message = "被叫号码不能为空") String mobile, String content) {
        this(mobile, content, 2);
    }

    public SendSmsModel(@NotEmpty(message = "被叫号码不能为空") String mobile,String content,Integer smsType) {
        serviceId = 35L;
        account = "lexintong";
        password = "qwer3324";
        this.callNo = DEFAULT_CALL_NO;
        this.mobile = mobile;
        this.content = content;
        //smsType是给恒世信通用 短信类型 1 营销短信（包括验证码），默认； 2 5g短信
        this.smsType = smsType;
        log.info("发送短信type:{}",smsType);
    }
    public SendSmsModel(@NotEmpty(message = "被叫号码不能为空") String mobile,String content ,String callNo) {
        serviceId = 35L;
        account = "lexintong";
        password = "qwer3324";
        this.callNo = callNo;
        this.mobile = mobile;
        this.content = content;
//        String validCode = randomCode();
//        this.validCode = validCode;
//        content = "您的登录验证码为 "+ validCode +" 请于10分钟内登录，过期需重新发送短信验证码。";
    }

    public SendSmsModel(@NotEmpty(message = "被叫号码不能为空") String mobile,String content ,String callNo ,String validCode) {
        serviceId = 35L;
        account = "lexintong";
        password = "qwer3324";
        this.callNo = callNo;
        this.mobile = mobile;
        this.content = content;
//        String validCode = randomCode();
        this.validCode = validCode;
//        content = "您的登录验证码为 "+ validCode +" 请于10分钟内登录，过期需重新发送短信验证码。";
    }

    public static String randomCode() {
        StringBuilder str = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < 6; i++) {
            str.append(random.nextInt(10));
        }
        return str.toString();
    }

}
